package engine.logic
{
	import flash.display.Bitmap;
	import flash.utils.Dictionary;
	
	import newx.com.ResManager;
	
	public class BitMapPool
	{	
		private static	var _bitMapList	:Dictionary	= new Dictionary( true );
		
		public static function borrowBitmap( name : String ):Bitmap
		{
//			trace("------------ borrowBitMap = " + name );
			var bt : Bitmap;
			
			if( null == _bitMapList[name] )
			{
				_bitMapList[name] = [];
			}
			
			if( 0 == _bitMapList[name].length )
			{
				bt	=	ResManager.newResClass( name ) as Bitmap;
			}else
			{
				bt	=	_bitMapList[name].shift();
			}
			if( bt is Bitmap )
			{
				bt["name"] = name;
			}
			
			return bt;
		}
		
		public static function returnBitmap( name : String, bitMap : Bitmap ):void
		{
//			trace("------------ returnBitMap = " + name);

			if( null == bitMap ) return;;
			
			if( null == _bitMapList[name] )
			{
				_bitMapList[name] = [];
			}
			
			_bitMapList[name].push( bitMap );
		}
		
	}
}